﻿using System;
using System.Collections.Generic;
using System.Reflection;
using xycn.pluginsupport;
using xycn.pluginsupport.ControllerPlugins;

namespace xycn.framework.ControllerManagement
{
    /// <summary>
    /// WEB API Controller信息
    /// </summary>
    public class ControllerInfor
    {
        /// <summary>
        /// controller所在库信息
        /// </summary>
        public string fromLib = "";

        /// <summary>
        /// 所在命名空间
        /// </summary>
        public string Namespace = "";

        /// <summary>
        /// controller类名
        /// </summary>
        public string className = "";

        /// <summary>
        /// controller路由
        /// </summary>
        public List<Route> controllerRoutes = new List<Route>();

        /// <summary>
        /// congroller类型
        /// </summary>
        public Type controllerType = null;

        /// <summary>
        /// controller中处理http 请求的函数列表
        /// </summary>
        public List<ControllerMethodInfor> methodInfors =
            new List<ControllerMethodInfor>();
    }

    public enum MethodAttribute
    {
        HttpMethod, HttpMethodWithContext,
        ActionMethod, ActionWithContext
    }

    /// <summary>
    /// WEB API Controller中Http处理函数信息
    /// </summary>
    public class ControllerMethodInfor
    {
        /// <summary>
        /// 函数信息
        /// </summary>
        public MethodInfo methodInfor = null;

        /// <summary>
        /// 函数名
        /// </summary>
        public string Name = "";


        /// <summary>
        /// 授权角色 true表示需要授权 false不需要授权 默认需要true授权 liuxijin 20210329 
        /// </summary>
        public bool IsAuth { get; set; } = true;

        /// <summary>
        /// 函数对应的处理http请求的类型
        /// </summary>
        public HttpMethodType httpMethodType;

        /// <summary>
        /// 函数是否标记为通过HttpContext对象来处理Http请求
        /// </summary>
        public MethodAttribute methodAttrType;

        /// <summary>
        /// 函数的HttpMethod或HttpMethoWithContext对象
        /// </summary>
        public object methodAttr = null;

        /// <summary>
        /// 函数对应的路由属性
        /// </summary>
        public List<Route> routeAttr = new List<Route>();

        /// <summary>
        /// 函数需要输入的参数
        /// </summary>
        public List<MethodParmeter> Parameters =
            new List<MethodParmeter>();

        /// <summary>
        /// 函数返回类型
        /// </summary>
        public Type returnType = null;
    }

    /// <summary>
    /// 用于缓存控制器的http请求处理函数的参数信息
    /// </summary>
    public class MethodParmeter
    {
        /// <summary>
        /// 参数类型
        /// </summary>
        private Type _parmeterType = null;
        public Type parmeterType { get { return _parmeterType; } set { _parmeterType = value; } }

        /// <summary>
        /// 参数名
        /// </summary>
        private string _Name = "";
        public string Name { get { return _Name; } set { _Name = value; } }

        /// <summary>
        /// 参数对应的属性
        /// </summary>
        private string _Attribute = "";
        public string Attribute { get { return _Attribute; } set { _Attribute = value; } }
    }
}
